package com.xianggu.designMode.iterationMethod.demo1;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.function.Consumer;

/**
 * @author chengjy
 * @date 2025/3/19
 */
public class IterationDemo {
    public static void main(String[] args) throws IOException {
        List<String> strings = Files.readAllLines(new File("D:\\javaDemo\\xiangGu\\xiangGu\\Springboot-xiangGu\\src\\main\\resources\\demo.user").toPath());

        readUsers(System.out::println);

        System.out.println("-----------------------------------");
        //迭代输出
        for (User user : new UserRead(strings)) {
            System.out.println(user);
        }
    }

    private static void readUsers(Consumer<User> userConsumer) throws IOException {
        List<String> strings = Files.readAllLines(new File("D:\\javaDemo\\xiangGu\\xiangGu\\Springboot-xiangGu\\src\\main\\resources\\demo.user").toPath());
        for (String textLine : strings) {
            String[] split = textLine.substring(1, textLine.length() - 1).split(",");
            User user = new User(split[0], Integer.parseInt(split[1]));
            userConsumer.accept(user);
        }
    }
}
